package com.czxy.tanhua.service;

import com.czxy.tanhua.autoconfig.template.FaceTemplate;
import com.czxy.tanhua.autoconfig.template.OssTemplate;
import com.czxy.tanhua.dubbo.api.UserInfoApi;
import com.czxy.tanhua.entity.UserInfo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @Author 爱吃豆的土豆、
 * @Date 2023/4/3 9:41
 */
@Service
public class UserInfoService {
    @Resource
    private OssTemplate ossTemplate;
    @Resource
    private FaceTemplate faceTemplate;
    @DubboReference
    private UserInfoApi userInfoApi;
    public void adduserinfo(UserInfo userInfo) {
        userInfoApi.adduserInfo(userInfo);
    }

    public void uploadHead(MultipartFile headphoto, Long id) {
        String imageUrl = ossTemplate.upload(headphoto);

        boolean flag = faceTemplate.FaceUtils(imageUrl);
        if (!flag){
            throw new RuntimeException("不包含人脸");
        }
        UserInfo userInfo = new UserInfo();
        userInfo.setId(id);
        userInfo.setAvatar(imageUrl);
        userInfoApi.update(userInfo);
    }
}
